#ifndef PINQLISTVIEW_H
#define PINQLISTVIEW_H

#include <QikViewBase.h>
#include <PinQ.mbg>
#include "PinQTask.h"
#include "PinQModel.h"
#include "PinQAppUi.h"
#include "PinQ.hrh"

class CQikListBox;
class CQikCommandManager;
class MQikListBoxData;
class MQikListBoxModel;

class CPinQListView : public CQikViewBase, public MQikListBoxObserver
	{
public:
	static CPinQListView* NewLC(CQikAppUi& aAppUi,
			const TVwsViewId aParentViewId);
	~CPinQListView();
	TVwsViewId ViewId() const;
	void RefreshListBoxL(); // from CategoryChanged
	void TaskStateChangedL(const CPinQTask& aTask, CPinQTask::TState aNewState);

protected:
	void ViewActivatedL(const TVwsViewId &aPrevViewId, TUid aCustomMessageId,
			const TDesC8 &CustomMessage);
	CQikCommand* DynInitOrDeleteCommandL(CQikCommand* aCommand,
			const CCoeControl& aControlAddingCommands);
	void ViewConstructL();
	void CPinQListView::SaveL();

private:
	CPinQListView(CQikAppUi& aAppUi, const TVwsViewId aParentViewId);
	void ConstructL();

	inline CPinQAppUi& PinQAppUi() const
		{
		return static_cast<CPinQAppUi&>(iQikAppUi);
		}
	inline CPinQModel& PinQModel() const
		{
		return static_cast<CPinQAppUi&>(iQikAppUi).PinQModel();
		}

	void HandleCommandL(CQikCommand& aCommand);
	void HandleListBoxEventL(CQikListBox* aListBox,
			TQikListBoxEvent aEventCategory, TInt aItemIndex, TInt aSlotId);

	void OnChangeTaskCmdL();
	void OnViewPacketsCmdL();
	void OnNewTaskCmdL();
	void OnDeleteTaskCmdL();
	void OnUndoDeleteTaskCmdL();
	void OnTaskUpdatedL(TUid aUid); //after "Change View"
//	void OnTaskDeletedL(const TUid& aUid);// after Delete in change View. Removed as dupl.

	void RefreshListBoxL(CQikListBox& aListBox);
	void AddTaskL(MQikListBoxModel& aModel, CPinQTask& aTask) const; //Internal of Refres and Updated
	void SetIconL(MQikListBoxData& ListBoxData, TMbmPinq icon, TMbmPinq mask) const;
	void SetSlot2L(const CQikListBox& aListbox, TInt aIndex,
					const TDesC& aText) const;
	void SetSlot2AndIconL(const CQikListBox& aListbox, TInt aIndex,
			const TDesC& aText, TMbmPinq aIcom, TMbmPinq aMask) const;
	
	void UpdateCmds(TBool aAvailable) const;
	void UpdateCmds(); 
	void UpdateCmds(CQikListBox& aListbox) const; 
	void UpdateCmds(CPinQTask::TState aState) const;
	void UpdateCmds(CQikListBox& aListbox, TInt aItemIndex) const;
//	void UpdateSelectCmd();
//	void UpdateSelectCmd(CPinQTask::TState aState) const;//curernt==Active: Edit+Stop | Edit+Start
//	void UpdateSelectCmd(CQikListBox& aListbox) const;//active unknown New|UpdateSelectCmd(CPinQTask::TState aState) 
//	void UpdateMarkCmds() const;
//	void UpdateMarkCmds(const CQikListBox& aListbox) const;

	void SwitchTaskStateL(CQikListBox& aListbox, TInt aItemIndex) const;
	void SwitchTaskStateL() const;

	void SetZoomFactorL(TInt aZoomLevel);

	static TInt Compare(const MQikListBoxData& aFirst,
			const MQikListBoxData& aSecond);

	// const;
	//inline CQikListBox& ListBox() {return *(LocateControlByUniqueHandle<CQikListBox>(EPinQListViewListCtrl));}
	/*	
	 virtual void Started();
	 virtual void Finished();
	 virtual void Cancelled();
	 virtual void Sent();
	 */

private:
	CQikCommandManager& iCommandManager;
	CQUiConfigClient& iConfigClient;
	};

#endif // PINQLISTVIEW_H
